package org.geekang.bigdata.hbase;

import java.io.IOException;

public class HBaseMain {
    public static void main(String[] args) {
        HBaseRepository repository = new HBaseRepository();
        String[] colFamily = {"info", "score"};
        String[] info_cols = {"student_id", "class"};
        String[] score_cols = {"understanding", "programming"};
        String tableName = "syc_test:student";

        try {
            repository.init();
            System.out.println("连接HBase成功!");

            repository.createTable(tableName, colFamily);
            System.out.println("创建student表成功！");

            repository.insertOrUpdate(tableName, "Tom", colFamily[0], info_cols, new String[]{"20210000000001", "1"});
            repository.insertOrUpdate(tableName, "Tom", colFamily[1], score_cols, new String[]{"75", "82"});
            repository.insertOrUpdate(tableName, "Jerry", colFamily[0], info_cols, new String[]{"20210000000002", "1"});
            repository.insertOrUpdate(tableName, "Jerry", colFamily[1], score_cols, new String[]{"85", "67"});
            repository.insertOrUpdate(tableName, "Jack", colFamily[0], info_cols, new String[]{"20210000000003", "2"});
            repository.insertOrUpdate(tableName, "Jack", colFamily[1], score_cols, new String[]{"80", "80"});
            repository.insertOrUpdate(tableName, "Rose", colFamily[0], info_cols, new String[]{"20210000000004", "2"});
            repository.insertOrUpdate(tableName, "Rose", colFamily[1], score_cols, new String[]{"60", "61"});
            repository.insertOrUpdate(tableName, "Shi", colFamily[0], info_cols, new String[]{"G20210735010106", "1"});
            System.out.println("数据插入成功！");

            repository.printTable(tableName);

            repository.deleteTable(tableName);
            System.out.println("表删除成功！");

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            repository.close();
        }
    }
}
